<style type="text/css">
    .layui-form-select dl{z-index:9999;}
</style>
<form class="layui-form layui-form-pane" action="{:url()}" method="post" id="editForm">
    <div class="page-form">

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline w200">
                <input type="text" class="layui-input field-name" name="name" lay-verify="required" autocomplete="off" placeholder="起个名字前台不展示">
            </div>
            <div class="layui-form-mid layui-word-aux">必填项</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图片</label>
            <div class="layui-input-inline upload">
                <button type="button" name="img" class="layui-btn layui-btn-primary layui-upload" lay-type="image" lay-data="{accept:'image'}">请上传图片</button>
                <input type="hidden" class="upload-input field-img" name="img">
                {if condition="!empty($data_info['img'])"}
                <img src="{$data_info['img']}" style="border-radius:5px;border:1px solid #ccc" width="36" height="36">
                {else /}
                <img src="" style="display:none;border-radius:5px;border:1px solid #ccc" width="36" height="36">
                {/if}
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                <input type="radio" class="field-type" name="type" value="1" title="小程序内页面" checked>
            </div>
            <div class="layui-input-inline" style="margin-left:-55px;">
                <input type="radio" class="field-type" name="type" value="2" title="其他小程序">
            </div>
              <div class="layui-input-inline" style="margin-left:-55px;">
                <input type="radio" class="field-type" name="type" value="3" title="h5网页">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">跳转地址</label>
            <div class="layui-input-inline w200">
                <input type="text" class="layui-input field-path" name="path" lay-verify="required" autocomplete="off" placeholder="例如/pages/index/index">
            </div>
            <div class="layui-form-mid layui-word-aux">必填项</div>
        </div>
        <div class="layui-form-item" id="appid" style="display: none;">
            <label class="layui-form-label">appid</label>
            <div class="layui-input-inline w200">
                <input type="text" class="layui-input field-appid" name="appid" autocomplete="off" placeholder="要跳转的小程序的appid">
            </div>
            <div class="layui-form-mid layui-word-aux">必填项</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">顺序</label>
            <div class="layui-input-inline w200">
                <input type="text" class="layui-input field-shunxu" name="shunxu" lay-verify="required" autocomplete="off" placeholder="单位数字，数字越大越靠前">
            </div>
            <div class="layui-form-mid layui-word-aux">必填项</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态设置</label>
            <div class="layui-input-inline">
                <input type="radio" class="field-status" name="status" value="1" title="启用" checked>
                <input type="radio" class="field-status" name="status" value="0" title="禁用">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" class="field-id" name="id">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="formSubmit">提交</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary ml10"><i class="aicon ai-fanhui"></i>返回</a>
            </div>
        </div>
    </div>
</form>

{include file="admin@block/layui" /}
<script>
    var formData = {:json_encode($data_info)};
    layui.use(['upload'], function() {
        var $ = layui.jquery, layer = layui.layer, upload = layui.upload;
        upload.render({
            elem: '.layui-upload'
            ,url: '{:url("admin/annex/upload?thumb=no&water=no")}'
            ,method: 'post'
            ,before: function(input) {
                layer.msg('文件上传中...', {time:3000000});
            },done: function(res, index, upload) {
                var obj = this.item;
                if (res.code == 0) {
                    layer.msg(res.msg);
                    return false;
                }
                layer.closeAll();
                var input = $(obj).parents('.upload').find('.upload-input');
                if ($(obj).attr('lay-type') == 'image') {
                    input.siblings('img').attr('src', res.data.file).show();
                }
                var curWwwPath = window.document.location.href;
                var pathName = window.document.location.pathname;
                var pos = curWwwPath.indexOf(pathName);

                console.log(curWwwPath.substring(0, pos) + res.data.file);
                input.val(res.data.file);
            }
        });
    });

</script>


{:editor(['content'])}

<script>
    var formData = {:json_encode($data_info)};
</script>
<script src="__ADMIN_JS__/footer.js"></script>

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
    //点击类型显示不同
    $(function () {
        setTimeout(function () {
            $('.layui-form-radio').click(function() {
                var cur = $(this).parent().find('input[name=type]');
                console.log(cur.val());
                if(cur.val() == 2) {
                    $('#appid').css("display","block");
                }else{
                    $('#appid').css("display","none");
                }
            });


        },500)
        if($('input[name=type]:checked').val() == 2) {
            $('#appid').css("display","block");
        }
    });
</script>
